//
//  CGSearchBar.m
//  SchoolClient
//
//  Created by mac on 15/10/27.
//  Copyright © 2015年 mac. All rights reserved.
//

#import "CGSearchBar.h"

@implementation CGSearchBar

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        self.font = [UIFont systemFontOfSize:14];
        UIImage *bgImage = [UIImage imageNamed:@"login_input_phone_bg"];
        //bgImage = [bgImage stretchableImageWithLeftCapWidth:bgImage.size.width * 0.5 topCapHeight:bgImage.size.height * 0.5];
        self.background = bgImage;
        
        UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"navigationbar_search_icon"]];
        imageView.width += 10;
        imageView.contentMode = UIViewContentModeCenter;
        NSLog(@"frame:%@",NSStringFromCGRect(imageView.frame));
        self.leftView = imageView;
        //想要显示搜索框左边的视图，一定要设置左边视图的模式
        self.leftViewMode = UITextFieldViewModeAlways;
    }
    
    return self;
}

/*
//重写leftView方法，使图片距离左边框10mm
-(CGRect)leftViewRectForBounds:(CGRect)bounds{
    CGRect iconRect = [super leftViewRectForBounds:bounds];
    iconRect.origin.x += 10;
    iconRect.size.width += 5;
    iconRect.size.height += 5;
    return iconRect;
}
*/

@end
